<!DOCTYPE HTML>
<html style="background: #f9f9f9">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>法援宝</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../css/style.css" />
    <link rel="stylesheet" type="text/css" href="../css/lawyer_user.css" />
    <script type="text/javascript" src="../script/api.js"></script>
    <script type="text/javascript" src="../script/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="../script/mobile.js"></script>
    <script type="text/javascript" src="../script/lawyer.js"></script>

    <script type="text/javascript" src="../script/mobile-detect.js"></script>
    <script type="text/javascript" src="../script/mobile-detect.min.js"></script>

</head>
<body style="background: #f9f9f9">
<div id="secHeader">
  <header class="header">
      <a href="javascript:void(0);" onclick="comeBack()"  class="back_btn"><img src="../image/head-fanhui.png" alt=""></a>
      <h2>绑定手机号</h2>

  </header>
</div>

<section class="login_section">
    <div class="fyb_logo"><img src="../image/fyb_logo.png" alt=""></div>
    <div class="login_box">
        <ul>
            <li class="username"><input type="text" placeholder="请输入手机号" name='phone' id='phone' value=""></li>
            <li class="tel_code"><input type="text" placeholder="请输入验证码" name='yzm'><span id='regyzm'>获取验证码</span></li>
            <li class="tel_code"><input style="width:100%;" type="password" placeholder="请输入密码" name='password'></li>
        </ul>

        <button class="login_submit" type="submit" onclick="login()">确认绑定</button>
    </div>

</section>

</body>

<script>
    var usertype=1
    var para;
    //alert('请绑定手机号！');
    apiready = function(){
      $api.fixStatusBar( $api.dom('#secHeader') );
      api.setStatusBarStyle({
          style: 'light'
      });
      para = api.pageParam;

    }

    $('#regyzm').click(function () {
        if($(this).hasClass('regyzm')==false){
            var phone=$('input[name=phone]').val();
            if(phone==''){
                alert("请输入手机号！");return;
            }else if(!/^1[345678]\d{9}$/.test(phone)){
                alert("手机号格式错误！");return;
            }

            var p={phone:phone,type:1};
             api.ajax({
                url: webSiteUrl+'/app/public/yzm',
                method: 'post',
                data: {
                    values:p
                }
            }, function(ret, err) {


                if(ret.code==200){

                    $('#regyzm').addClass('regyzm');
                    var num=60;
                    timer=setInterval(function(){
                        $('#regyzm').html(num+'秒');
                        num--;
                        if(num==0){
                            clearInterval(timer);
                            timer=null;
                            $('#regyzm').html('重新获取');
                            $('#regyzm').removeClass('regyzm');
                        }
                    },1000)

                    alert(ret.msg);


                }else{alert(ret.msg)}
            });

        }
    })
    function login(){
        var phone=$("input[name=phone]").val();
        var yzm=$("input[name=yzm]").val();
        var pwd=$("input[name=password]").val();
        if(phone==''){
            alert("请输入手机号！");return;
        }else if(!/^1[345678]\d{9}$/.test(phone)){
            alert("手机号格式错误！");return;
        }else if(yzm==''){
            alert("请输入验证码！");return;
        }else if(pwd.length<6){
            alert("密码不少于6位数");return;
        }

        para.data['phone'] = phone;
        para.data['password'] = pwd;
        para.data['yzm'] = yzm;

        var threeinfo= $api.getStorage('threeinfo');
        //alert(JSON.stringify(para.data))

        api.ajax({
            url: webSiteUrl+'/App/public/three',
            method: 'post',
            data: {
                values: para.data
            }
        }, function(ret, err) {
            console.log(JSON.stringify(ret))
            if(ret.code==200){
              $api.clearStorage();
              $api.setStorage("user",ret.data);
              aaplay('workbench')

            }else {
              alert(ret.msg);
            }

        })
  }



</script>
</html>
